package wqh.controller.json;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wqh.domain.AlarmNoneInfor;
import wqh.pojo.MapRet;
import wqh.service.AlarmNoneInforService;

import java.util.List;

/**
 * Created by devts on 2016/11/11.
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping(value = "/dev")
public class AlarmNoneInforJSON {

    private static Logger logger = LoggerFactory.getLogger(AlarmNoneInforJSON.class);

    @Autowired
    private AlarmNoneInforService alarmNoneInforService;

    @RequestMapping(value = "/getAll",method = RequestMethod.GET)
    public Object getAll(){
        List<AlarmNoneInfor> alarmNoneInforList = alarmNoneInforService.findAllRecord();
        return MapRet.DATA(alarmNoneInforList);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    public Object delete(@RequestParam(value = "id", required = true) int id)
    {
        try {
            alarmNoneInforService.deleteById(id);
            return MapRet.SQL_DELETE_SUCCESS();
        }catch (Exception e)
        {
            e.printStackTrace();
            logger.error("删除无记录回路号的火警出错：" + e);
            return MapRet.SQL_DELETE_ERROR();
        }
    }

    @RequestMapping(value = "/deleteAll",method = RequestMethod.GET)
    public Object deleteAll()
    {
        try {
            alarmNoneInforService.deleteAll();
            return MapRet.SQL_DELETE_SUCCESS();
        }catch (Exception e)
        {
            e.printStackTrace();
            logger.error("删除无记录回路号的所有火警出错：" + e);
            return MapRet.SQL_DELETE_ERROR();
        }
    }

}
